﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using Shpm.App.Input.Bean;
using Shpm.App.Input.Dao;
using Shpm.App.Master.Bean;
using Shpm.App.Master.Dao;
using Shpm.App.Commons.Db.Beans.Master;
using Shpm.System;
using Shpm.App.Commons.Utils;
using System.Reflection;
using Shpm.System.Web.Control;
using log4net;

public partial class App_Input_PersonInfoWelfare : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            if (Context.Items.Contains("PERSON_ID"))
            {
                ViewState["PERSON_ID"] = Context.Items["PERSON_ID"];
            }
            else
            {
                ViewState["PERSON_ID"] = null;
            }
            if (Context.Items["EMPLOYEE_ID"] != null)
            {
                ViewState["EMPLOYEE_ID"] = Context.Items["EMPLOYEE_ID"];
            }
            else
            {
                ViewState["EMPLOYEE_ID"] = null;
            }
            // 接收传递参数为分页编号
            if (Context.Items.Contains("ParamPageIndex"))
            {
                ViewState["ParamPageIndex"] = Convert.ToString(Context.Items["ParamPageIndex"]);
            }
            // 接收传递参数为父页编号
            if (Context.Items.Contains("URL"))
            {
                ViewState["URL"] = Convert.ToString(Context.Items["URL"]);
            }
            if (Context.Items.Contains("CMB_GROUP_ID"))
            {
                this.ViewState["CMB_GROUP_ID"] = Context.Items["CMB_GROUP_ID"];
            }
            if (Context.Items.Contains("CMB_JOB_ID"))
            {
                this.ViewState["CMB_JOB_ID"] = Context.Items["CMB_JOB_ID"];
            }
            if (Context.Items.Contains("EMPLOYEE_STATUS"))
            {
                this.ViewState["EMPLOYEE_STATUS"] = Context.Items["EMPLOYEE_STATUS"];
            }
            //ViewState["EMPLOYEE_ID"] = "tan9";
            //ViewState["PERSON_ID"] = 149;
            //ViewState["STATE"] = "INS";
            dataBound();
            if (Convert.ToString(ViewState["EMPLOYEE_STATUS"]) == "-1")
            {
                btnAdd.Enabled = false;
            }
            else
            {
                btnAdd.Enabled = true;
            }
        }
    }

    #region 设置标签
    protected void lnkTab_Command(object sender, CommandEventArgs e)
    {
        string directUrl = "~/App/Input/SaleProcesseMembershipForm.aspx";
        switch (e.CommandName)
        {
            case "btn0":
                // 基本信息
                // this.LinkButton1.CssClass = "selectli";
                // this.LinkButton2.CssClass = "";
                directUrl = "~/App/Input/PersonInfoForm.aspx";
                break;
            case "btn1":
                // 学历
                directUrl = "~/App/Input/PersonInfoEdu.aspx";
                break;
            case "btn3":
                // 工作经历
                directUrl = "~/App/Input/PersonInfoWork.aspx";
                break;
            case "btn2":
                // 家庭情况
                directUrl = "~/App/Input/PersonInfoFamily.aspx";
                break;
            case "btn4":
                // 福利
                directUrl = "~/App/Input/PersonInfoWelfare.aspx";
                break;
            case "btn5":
                //薪酬
                directUrl = "~/App/Input/PersonInfoSalaryForm.aspx";
                break;
            case "btn6":
                //奖惩
                directUrl = "~/App/Input/PersonBonusPenaltyForm.aspx";
                break;
            case "btn7":
                //报道
                directUrl = "~/App/Input/PersonPrepareForm.aspx";
                break;
            case "btn8":
                //培训
                directUrl = "~/App/Input/PersonTrainForm.aspx";
                break;
            default:
                break;
        }
        if (!string.IsNullOrEmpty(Convert.ToString(this.ViewState["PERSON_ID"])))
        {
            Context.Items["PERSON_ID"] = this.ViewState["PERSON_ID"];
            Context.Items["EMPLOYEE_ID"] = this.ViewState["EMPLOYEE_ID"];
            Context.Items["CMB_JOB_ID"] = ViewState["CMB_JOB_ID"];
            Context.Items["CMB_GROUP_ID"] = ViewState["CMB_GROUP_ID"];
            Context.Items["ParamPageIndex"] = ViewState["ParamPageIndex"];
            Context.Items["URL"] = ViewState["URL"];
            Context.Items["EMPLOYEE_STATUS"] = ViewState["EMPLOYEE_STATUS"];
            ControllerUtils.Transfer(this.Context, directUrl, false);
        }
        else
        {
            ((Design_MasterPage)this.Master).InfoMessage =
                          HttpContext.GetGlobalResourceObject(Constants.GLOBAL_RESOURCE_NAME, "I0035").ToString();
        }

    }
    #endregion

    protected void btnAdd_Click(object sender, EventArgs e)
    {
        SaveBase();
    }

    /*
     * 函数名：dataBound
     * 功能：数据绑定
     * 参数：无
     * 说明：
     */
    private void dataBound()
    {
        if (this.ViewState["EMPLOYEE_ID"] != null)
        {
            PersonEmployeeBean dataBean = new PersonEmployeeBean();
            PersonEmployeeBean newBean = new PersonEmployeeBean();
            PersonEmployeeDao Dao = new PersonEmployeeDao();
            dataBean.EmployeeId = Convert.ToString(ViewState["EMPLOYEE_ID"]);
            newBean = Dao.GetEnployeeId(dataBean);
            if (newBean != null)
            {
                this.rbl1.SelectedValue = (this.rbl1.Items.FindByValue(newBean.EmployeeRelation) == null) ? null : newBean.EmployeeRelation;
                this.memo.Text = newBean.EmployeeRelationMemo;
                this.employeedole.Text = newBean.EmployeeDole;
                this.employeerecord.Text = newBean.EmployeeRecord;
                this.employeeAccumulationAccount.Text = newBean.EmployeeAccumulationAccount;
                switch (newBean.EmployeeInsurance)
                {
                    case"1":
                        rb1.Checked = true;
                        break;
                    case "2":
                        rb2.Checked = true;
                        break;
                    case "3":
                        rb3.Checked = true;
                        break;
                    case "4":
                        rb4.Checked = true;
                        break;
                    case "5":
                        rb5.Checked = true;
                        break;
                    default:
                        rb1.Checked = true;
                        break;
                }
                switch (newBean.EmployeeAccumulation)
                {
                    case "1":
                        rbAcc1.Checked = true;
                        break;
                    case "2":
                        rbAcc2.Checked = true;
                        break;
                    case "3":
                        rbAcc3.Checked = true;
                        break;
                    case "4":
                        rbAcc4.Checked = true;
                        break;
                    case "5":
                        rbAcc5.Checked = true;
                        break;
                    default:
                        rbAcc1.Checked = true;
                        break;
                }
            }
        }
    }


    /*
     * 函数名：SaveBase
     * 功能：数据保存
     * 参数：无
     * 说明：
     */
    private void SaveBase()
    {

        SysUserManager manager = new SysUserManager(Context);
        string userId = manager.getSysUserBean().getMstSysUserBean().SysUserId;
        PersonEmployeeBean dataBean = new PersonEmployeeBean();
        PersonEmployeeDao dao = new PersonEmployeeDao();
        dataBean.EmployeeRelation = rbl1.SelectedValue;
        dataBean.EmployeeRelationMemo = this.memo.Text;
        dataBean.EmployeeDole = this.employeedole.Text;
        dataBean.EmployeeRecord = this.employeerecord.Text;
        dataBean.EmployeeAccumulationAccount = this.employeeAccumulationAccount.Text;
        string strInsurance = Request.Form["ctl00$ContentPlaceHolder1$Insurange"];
        dataBean.EmployeeInsurance = strInsurance.Substring(2);
        string strAccumul = Request.Form["ctl00$ContentPlaceHolder1$Accum"];
        dataBean.EmployeeAccumulation = strAccumul.Substring(5);
        dataBean.UserId = userId;
        
        if (this.ViewState["EMPLOYEE_ID"] != null)
        {
            dataBean.EmployeeId = Convert.ToString(ViewState["EMPLOYEE_ID"]);
            dao.UpdWelfare(dataBean);
            ((Design_MasterPage)this.Master).InfoMessage =
                          HttpContext.GetGlobalResourceObject(Constants.GLOBAL_RESOURCE_NAME, "I0002").ToString();
        }
    }
    protected void btnBack_Click(object sender, EventArgs e)
    {
        // 传递分页编号
        Context.Items["ParamPageIndex"] = ViewState["ParamPageIndex"];
        Context.Items["CMB_GROUP_ID"] = Convert.ToString(this.ViewState["CMB_GROUP_ID"]);
        Context.Items["CMB_JOB_ID"] = Convert.ToString(this.ViewState["CMB_JOB_ID"]);
        //string url = Convert.ToString(ViewState["URL"]);
        string url = "~/App/Input/PersonEmployeeSrhForm.aspx";
        ControllerUtils.Transfer(Context, url, true);    
    }
}
